package com.example.dailyrecord.controller;

import com.example.dailyrecord.base.controller.BaseController;
import com.example.dailyrecord.base.entity.ResultMsg;
import com.example.dailyrecord.entity.Record;
import com.example.dailyrecord.entity.StatusCode;
import com.example.dailyrecord.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/record")
@Api(tags = {"记录"})
public class RecordController extends BaseController<Record> {
    @Resource
    RecordService recordService;

    @GetMapping("/fun1")
    @ApiOperation(value = "周开始结束时间图", notes = "周开始结束时间图")
    public ResultMsg fun1(HttpServletRequest request, HttpServletResponse response) {
        return ResultMsg.getInstance(recordService.fun1(request, response), StatusCode.SUCCESS);
    }

    @GetMapping("/fun2")
    @ApiOperation(value = "科目学习时长图", notes = "科目学习时长图")
    public ResultMsg fun2(HttpServletRequest request, HttpServletResponse response) {
        return ResultMsg.getInstance(recordService.fun2(request, response), StatusCode.SUCCESS);
    }

    @GetMapping("/fun3")
    @ApiOperation(value = "科目学习时长比例图", notes = "科目学习时长比例图")
    public ResultMsg fun3(HttpServletRequest request, HttpServletResponse response) {
        return ResultMsg.getInstance(recordService.fun3(request, response), StatusCode.SUCCESS);
    }

    @GetMapping("/fun4")
    @ApiOperation(value = "科目学习时长排序图", notes = "科目学习时长排序图")
    public ResultMsg fun4(HttpServletRequest request, HttpServletResponse response) {
        return ResultMsg.getInstance(recordService.fun4(request, response), StatusCode.SUCCESS);
    }

    @ApiOperation(value = "系统自动设置完成")
    @Scheduled(cron = "0 30 23 * * ?")
    public void setFinished() {
        recordService.setFinished();
    }
}
